package com.farmer.news.controller;

import com.farmer.common.entity.AgriNews;
import com.farmer.common.result.Result;
import com.farmer.news.service.NewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 农业资讯控制器
 */
@Slf4j
@RestController
@RequestMapping("/news")
public class NewsController {

    @Autowired
    private NewsService newsService;

    @GetMapping("/list")
    public Result<?> getNewsList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String category,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) String keyword) {
        return newsService.getNewsList(pageNum, pageSize, category, status, keyword);
    }

    @GetMapping("/{newsId}")
    public Result<?> getNewsById(@PathVariable Long newsId) {
        return newsService.getNewsById(newsId);
    }

    @PostMapping
    public Result<?> addNews(@RequestBody AgriNews news) {
        return newsService.addNews(news);
    }

    @PutMapping
    public Result<?> updateNews(@RequestBody AgriNews news) {
        return newsService.updateNews(news);
    }

    @DeleteMapping("/{newsId}")
    public Result<?> deleteNews(@PathVariable Long newsId) {
        return newsService.deleteNews(newsId);
    }

    @GetMapping("/recommended")
    public Result<?> getRecommendedNews(@RequestParam(defaultValue = "10") Integer limit) {
        return newsService.getRecommendedNews(limit);
    }

    @GetMapping("/statistics")
    public Result<?> getNewsStatistics() {
        return newsService.getNewsStatistics();
    }
} 